﻿@{
    ViewBag.Title = "NewsGroup";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}


@section Header
{
    <script type="text/javascript">
        function openDialog(dialogName) {
            $('#' + dialogName).dialog('open');
            $('#' + dialogName + ' :text').val("");
            return false;
        }


        function deleteNewsGroup(groupName) {

            var newsGroup = { NewsGroupName: groupName };

            $.post("/News/DeleteNewsGroup/", newsGroup,
                  function (data, textStatus) {
                      if (data == 'success') {
                          window.location.href = "/News/NewsGroup/";
                      }
                      else { $.messager.alert('失败', data, 'error'); }
                  }
                );

        }

        function addNewsGroup() {
            //todo 验证重复输入



            if ($("#txt_NewsGroup").validatebox('isValid') == false) { return; }


            //参数对象
            var newsGroup = { NewsGroupName: $("#txt_NewsGroup").val() };

            $.post("/News/AddNewsGroup/", newsGroup,
                    function (data, textStatus) {
                        if (data == 'success') {
                            $('#addNewsGroup').dialog('close');

                            window.location.href = "/News/NewsGroup/";
                        }
                        else { $.messager.alert('失败', data, 'error'); }
                    }
                  );
        }


    </script>
}

<body>

    <p>
        <a id="btn" type="button" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="openDialog('addNewsGroup')">新增</a>
    </p>

    <div>
        <table style="width: 300px">

            <tr>
                <td>新闻组名称</td>
                <td></td>
            </tr>
            @foreach (string item in ViewBag.NewsGroup)
            {
                <tr>
                    <td>@item </td>
                    <td><a href="#" onclick="deleteNewsGroup('@item')">删除</a></td>
                </tr>    
            }
        </table>
    </div>



    @*隐藏层窗体*@
    <div id="addNewsGroup" class="easyui-dialog" title="新增新闻组" style="width: 350px; height: 300px;" modal="true" closed="true">
        新闻组名称：<input id="txt_NewsGroup" type="text" class="easyui-validatebox" required="true" />
        <br />
        <a href="#" onclick="addNewsGroup()">保存</a>
        <a href="#" onclick="$('#addNewsGroup').dialog('close');return false;">取消</a>
    </div>



</body>
